﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HandyControl.Controls;
using Om.Camera;

namespace OptoMeasure.Views
{
    /// <summary>
    /// CameraExpSetView.xaml 的交互逻辑
    /// </summary>
    public partial class CameraExpSetView : System.Windows.Window
    {
        private IBaseCamera _baseCamera;
        public CameraExpSetView(IBaseCamera baseCamera)
        {
            _baseCamera = baseCamera;
            InitializeComponent();

            this.Loaded += CameraExpSetView_Loaded;
        }

        private async void CameraExpSetView_Loaded(object sender, RoutedEventArgs e)
        {
            var exp = await _baseCamera.GetExposureValue();
            txtCurrExp.Text = exp.ToString();
        }

        private async void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (!int.TryParse(txtSetExp.Text.Trim(), out var val))
            {
                HandyControl.Controls.MessageBox.Error("曝光设定值错误。");
                return;
            }

            var res = await _baseCamera.SetExposureValue(val);
            if (!res)
            {
                HandyControl.Controls.MessageBox.Error("曝光值设定失败。");
                return;
            }
            this.Close();
        }
    }
}
